let common = {
    getFingerprint: function () {
        let excludes = {};
        excludes.userAgent = true;
        excludes.audio = true;
        excludes.enumerateDevices = true;
        excludes.fonts = true;
        excludes.fontsFlash = true;
        excludes.webgl = true;
        excludes.canvas = true;
        let options = {excludes: excludes}
        let fingerprint;
        Fingerprint2.get(options, function (components) {
            // 参数
            const values = components.map(function (component) {
                return component.value
            });
            // 指纹
            fingerprint = Fingerprint2.x64hash128(values.join(''), 31);
        });
        return fingerprint;
    },
    ajax: function (url, type, data, callback, async = false) {
        let parameter = {
            url: url,
            type: type,
            dataType: 'json',
            async: async,
            data: data,
            success: function (res) {
                if (res.code === 0) {
                    callback(res);
                } else {
                    layer.msg(res.msg, {icon: 5});
                }
            },
            error: function (res) {
                layer.msg('服务器请求错误', {icon: 5});
            }
        }
        layui.jquery.ajax(parameter);
    },
    msg: function (msg, isMsg = false, isConsole = true) {
        if (isMsg) {
            layer.msg(msg);
        }
        if (isConsole) {
            console.log(msg);
        }
    },
    socketOn: function (socket, event, callback) {
        socket.on(event, function (data) {
            if (data.code === 0) {
                common.msg(data.msg)
                callback(data.data);
            } else if (data.code === -1) {
                common.msg(data.msg, true)
            } else if (data.code === -2) {
                socket.close();
                alert(data.msg);
                // common.msg(data.msg, false, true)
            }
        });
    }

}

